<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
require_once './_AddinLibraries/database_driver.php';

/*******************************************************
 * This file includes the supporting PHP functions for teaching_class modules
 */

function get_type_list() {
    select_itec_database();
    $course_type = array();
    $sql = db_query("call sp_GetCourseType()");
    
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        $course_type[] = $erg['description'];
    };
    select_drupal_database();
    return $course_type;
}
function teachingclassID_list_query() {
    select_itec_database();
    $classes = array();
    $sql = db_query("call sp_GetTeachingClassList(null, null)");
    while ($erg = $sql->fetchAssoc()) {
        if ($erg == NULL)
            break;
        $classes[] = $erg['teachingclassid'];
    };
    select_drupal_database();
    return $classes;
}

function add_teaching_class($id,
                            $course,
                            $termid,
                            $status,
                            $bonus,
                            $lab,
                            $midterm,
                            $final,
                            $theoretical,
                            $practical)
{
    select_itec_database();
    $query = "call sp_AddTeachingClass('".$id."','".$course."','".$termid."',".$status.",".$bonus.",".$lab.",".$midterm.",".$final.",".$theoretical.",".$practical.")";
    $sql = db_query($query);
    $result = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result['result'];
}

function add_lecturer_to_teaching_class($lid, $tid, $role)
{
    select_itec_database();
    $sql = db_query("call sp_AddLecturerToTeachingClass('".$lid."','".$tid."','".$role."')");
    $result = $sql->fetchAssoc();
    select_drupal_database();
    return $result['result'];
}

function add_score($sid, $tid, $b, $l, $m, $f) {
    select_itec_database();
    $query = "call sp_ImportGrade('".$sid."','".$tid."',".$b.",".$l.",".$m.",".$f.")";
    $sql = db_query($query);
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    
    return $result['result'];
}

function add_student_to_teaching_class($sid, $tid)
{
    select_itec_database();
    $query = "call sp_AddStudentToTeachingClass('".$sid."','".$tid."')";
    $sql = db_query($query);
    $result = $sql->fetchAssoc();
    
    select_drupal_database();
    
    return $result['result'];
}

function find_lecturer($name) {
    select_itec_database();
    $query = "call sp_FindLecturer('".$name."')";
    $sql = db_query($query);
    $result  = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result;
}

function get_lecturer_id($name) {
    select_itec_database();
    $query = "call sp_GetLecturerID('".$name."')";
    $sql = db_query($query);
    $result = $sql->fetchAssoc();
    select_drupal_database();
    
    return $result['lecturerid'];
}

?>
